package com.climber.android.commonsdk.arouter

import android.content.Context

import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.SerializationService
import io.ganguo.library.mvp.util.GsonUtils

import java.lang.reflect.Type

/**
 * Created by Mikes at 2019/5/15 8:51 PM
 */
@Route(path = "/service/jsonParser")
class JsonServiceImpl : SerializationService {
    override fun init(context: Context) {

    }

    override fun <T> json2Object(text: String, clazz: Class<T>): T {
        return GsonUtils.fromJson(text, clazz)
    }

    override fun object2Json(instance: Any): String {
        return GsonUtils.toJson(instance)
    }

    override fun <T> parseObject(input: String, clazz: Type): T? {
        return GsonUtils.fromJson<T>(input, clazz)
    }
}
